
import 'package:flutter/material.dart';
import 'package:flutter_deer/index/iview/game_group_detail_iview.dart';
import 'package:flutter_deer/index/models/football_ratio_entity.dart';
import 'package:flutter_deer/index/models/user_betting_entity.dart';
import 'package:flutter_deer/mvp/base_page_presenter.dart';
import 'package:flutter_deer/net/base_entity.dart';
import 'package:flutter_deer/net/net.dart';
import 'package:flutter_deer/util/other_utils.dart';
import 'package:fixnum/fixnum.dart';


class GameGroupDetailPagePresenter extends BasePagePresenter<GameGroupDetailIMvpView> {

  @override
  void initState() {
  }

  Future<dynamic> fetchGroupDetail(String? groupId) async {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      asyncRequestNetwork<BaseEntity<FootballRatioGroupEntity>>(Method.get,
        url: HttpApi.gameGroupDetail.replaceAll("{groupId}", groupId.nullSafe),
        onSuccess: (data) {
          FootballRatioGroupEntity? groupEntity = data!.data;
          view.setFootballRatioGroup(groupEntity);
        },
          onError: (code,msg){
            dispose();
          }
      );
      asyncRequestNetwork<DoubleBaseEntity>(Method.get,
        url: HttpApi.residueGiveScore,
        onSuccess: (data) {
          view.setResidueGiveScore(data!.data);
        },
        onError: (code,msg){
          dispose();
        }
      );
    });
  }

  Future<dynamic> saveBetting(String? groupId,String? playWay,String? bettingType,String? useScoreType,double? score) async {
    UserBettingEntity userBettingEntity = new UserBettingEntity(isGroup: '1',groupId: groupId,playWay: playWay,bettingType: bettingType,useScoreType: useScoreType,score: score,ratioId: '0',orderNo: '');
    return asyncRequestNetwork<StringBaseEntity>(Method.post,
      url: HttpApi.saveBetting,
      params: userBettingEntity.toJson(),
      onSuccess: (data) {
        view.setBettingResult(data!.data);
      },
        onError: (code,msg){

        }
    );
  }

  // Future<dynamic> getGroupDetail(int? groupId) async {
  //   return asyncRequestNetwork<BaseEntity<FootballRatioGroupEntity>>(Method.get,
  //     url: HttpApi.gameGroupDetail.replaceAll("{groupId}", groupId.toString()),
  //     onSuccess: (data) {
  //       FootballRatioGroupEntity? groupEntity = data!.data;
  //       print('groupEntity groupEntity groupEntity groupEntitygroupEntity groupEntitygroupEntity');
  //       print(groupEntity);
  //       view.setFootballRatioGroup(groupEntity);
  //     },
  //   );
  // }

}